package sample;

import java.awt.Color;
import java.awt.Graphics;

public class Vertex {
	private int x;
	private int y;
	private int index;
	private int radius;
	private boolean isGuardOn;
	private static final int defaultRadius = 6;
	private boolean isSelected;

	
	public Vertex(){
		this.x = 0;
		this.y = 0;
		this.index = 0;
		this.isGuardOn = false;
		this.radius = defaultRadius;
		this.isSelected = false;
	}
	
	public Vertex(Vertex v){
		this.x = v.x;
		this.y = v.y;
		this.index = v.index;
		this.isGuardOn = v.isGuardOn;
		this.radius = defaultRadius;
		this.isSelected = v.isSelected;	
	}
	
	Vertex(int x, int y, int index){
		this.x = x;
		this.y = y;
		this.index = index;
		this.isGuardOn = false;
		this.radius = defaultRadius;
		this.isSelected = false;
	}
	
	public Vertex(int x, int y){
		this.x = x;
		this.y = y;
		this.isGuardOn = false;
		this.radius = defaultRadius;
		this.isSelected = false;
		this.index = 0;
	}
	
	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}

	public int getRadius() {
		return radius;
	}

	public void setRadius(int radius) {
		this.radius = radius;
	}
	
	public boolean isGuardOn() {
		return isGuardOn;
	}

	public void setGuardOn(boolean isGuardOn) {
		this.isGuardOn = isGuardOn;
	}

	public int getX() {
		return x;
	}
	
	public void setX(int x) {
		this.x = x;
	}
	
	public int getY() {
		return y;
	}
	
	public void setY(int y) {
		this.y = y;
	}
	
	public int getIndex() {
		return index;
	}
	
	public void setIndex(int index) {
		this.index = index;
	}
	
	public void setCoordinates(int x, int y){
		this.x = x;
		this.y = y;
	}
	
	public void incerementIndex(){
		this.index++;
	}
	
	public void decrementIndex(){
		this.index--;
	}
	
	public boolean isIntersected(Vertex v){
		if(Math.sqrt(Math.pow(Math.abs(this.getX() - v.getX()),2) + 
				Math.pow(Math.abs(this.getY() - v.getY()),2)) < 2*defaultRadius){
			return true;
		}
		else{
			return false;
		}
	}

	public String toString(){
		return "("+index+")";
		//return "("+index+" -> "+x+","+y+")";
	}
	
	public boolean equals(Object o)
	{
		Vertex v = (Vertex)o;
		if(this.x == v.x && this.y == v.y)
			return true;
		return false;
	}
	
	public void draw(Graphics g, Color c)
	{
		if(this.isSelected)
			g.setColor(Color.BLUE);
		else
			g.setColor(c);
		g.fillOval(this.getX() - this.getRadius() / 2, this.getY() - this.getRadius() / 2, this.getRadius(),
				this.getRadius());

		g.drawString("" + this.getIndex(), this.getX() + this.getRadius(), this.getY() + this.getRadius());
	}
}
